package com.hzncc.scaffold.controller.Front.Training;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.PageInfo;
import com.hzncc.scaffold.core.ResultT;
import com.hzncc.scaffold.entity.Other.Training;
import com.hzncc.scaffold.entity.Vo.TrainingListVo;
import com.hzncc.scaffold.service.TrainingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

/**
 * @Author: DrunkBear
 * @Date: 2022-06-08 17:35
 * @Description: null
 */
@Api(tags = "前台接口-实训中心")
@RequestMapping("/training")
@RestController
public class TrainingController {

    @Autowired
    TrainingService trainingService;

    @GetMapping("/list")
    @ApiOperation("实训中心列表")
    public ResultT list() {

        LambdaQueryWrapper<Training> lqw = new LambdaQueryWrapper<>();
        lqw.eq(Training::getStatus, 1);
        lqw.orderByDesc(Training::getStayAtTop);
        lqw.orderByDesc(Training::getSortTime);
        lqw.orderByDesc(Training::getId);
        List<Training> trainingList = trainingService.list(lqw);
        List<TrainingListVo> trainingListVos = BeanUtil.copyToList(trainingList, TrainingListVo.class);

//        PageInfo<TrainingListVo> info = new PageInfo<>();
//
//        info.setList(trainingListVos);
//        info.setTotal(new PageInfo<>(trainingList).getTotal());
        HashMap<String,Object> map = new HashMap<>();
        map.put("rows",trainingListVos);
        map.put("count",new PageInfo<>(trainingList).getTotal());
        return ResultT.success(map);
    }

    @GetMapping("/detail")
    @ApiOperation("根据编号查询实训中心资讯详细信息")
    public ResultT detail(Integer trainingId) {
        ResultT resultT = trainingService.detail(trainingId);
        return resultT;
    }
}
